var app = angular.module('myapp', ['ui.router']);
app.controller('main.ctrl', ['$scope', '$http', '$location', function ($scope, $http, $location) {
    var num = $location.search().pid;
    $http({
        url: '/product/getproductsbynum',
        method: 'get',
        params: {productNum: num}
    }).then(function (res) {
        for (var i = 0; i < res.data.data.length; i++) {
            var imgString = res.data.data[i].productImg;
            var imgarray = imgString.split(',');
            res.data.data[i].productImg = imgarray;
        }
        $scope.product = res.data.data[0];
        $scope.options ={
            productImgList:res.data.data[0].productImg,
            productName:res.data.data[0].productName
        }
    })
}]);
app.directive("slider", function () {
    return {
        restrict: 'ECMA',
        templateUrl: './tpls/slider.tpl.html',
        scope: {
            options: '='
        },
        link: function (scope, elements, attribute) {
            $(function () {
                if (scope.options.productImgList.length == 2) {
                    $('.carousel.carousel-slider').carousel({fullWidth: true, indicators: false});
                } else {
                    $('.carousel.carousel-slider').carousel({fullWidth: true, indicators: true});
                }
                $(".carousel").css("height", $(".carousel a img").height());
            });
        }
    }
});
app.config(['$stateProvider', '$locationProvider', '$urlRouterProvider', function ($stateProvider, $locationProvider, $urlRouterProvider) {
    $locationProvider.hashPrefix('');
    $stateProvider.state('detail', {
        url: '/detail',
        views: {
            'detailView': {
                templateUrl: './tpls/product-detail.tpl.html'
            }
        }
    }).state('parameter', {
        url: '/parameter',
        views: {
            'parameterView': {
                templateUrl: './tpls/product-parameter.tpl.html'
            }
        }
    }).state('comment', {
        url: '/comment',
        views: {
            'commentView': {
                templateUrl: './tpls/product-comment.tpl.html'
            }
        }
    });
    $urlRouterProvider.otherwise('detail')
}]);
var i = 0;//控制others显示隐藏
$('.others').click(function () {
    if (i % 2 == 0) {
        $('.others-open').addClass('fadeInDown').removeClass('fadeOutUp');
        i++;
    } else {
        $('.others-open').addClass('fadeOutUp').removeClass('fadeInDown');
        i++;
    }
});
//初始化模态框
$('.modal').modal();
$('.chioce-style').click(function () {
    $('footer').addClass('hidden');
});
$('.close-menu').click(function () {
    $('footer').removeClass('hidden');
});
//pro-tabs
$('.pro-tabs').click(function () {
    $('.pro-tabs').removeClass('active');
    $(this).addClass('active');
});
//back
$('.back').click(function () {
    history.back();
});


